package com.soft.mapper;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.soft.entity.Good;
import org.springframework.boot.test.context.SpringBootTest;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@SpringBootTest
public class GoodMapperTest {
	@Autowired
	private GoodMapper goodMapper;
	//@Test
	public void testSelect()
	{
		List<Good> goodList = goodMapper.selectList(null);
		for(int i = 0;i < goodList.size();i++)
		{
			System.out.println(goodList.get(i).getGoodName());
		}
	}
	//@Test
	public void testinsert() {
	    Good good = new Good();
	    good.setGoodName("王朝");
	    good.setGoodPrice("12");
	    good.setGoodamout("5");
	    goodMapper.insert(good);
	}
	//@Test
	public void updateTest() {
	    Good good = new Good();
	    good.setGoodId("1");
	    good.setGoodName("aaaa");
	    good.setGoodPrice("55");
	    goodMapper.updateById(good);
	}
	//@Test
	public void deleteTest() {
	    Good good = new Good();
	    good.setGoodId("2");
	    goodMapper.deleteById(good);
	}
	//@Test
	public void updateQueryTest() {
	    UpdateWrapper<Good> uw = new UpdateWrapper<>();
	    uw.gt("good_id", 2);
	    Good good = new Good();
	    good.setGoodName("雄安");
	    goodMapper.update(good, uw);
	}
	
	@Test
	public void selectOneTest() {
	    QueryWrapper<Good> qw = new QueryWrapper<>();
	    qw.gt("good_id", 2);
	    try {
	        Good good = goodMapper.selectOne(qw);
	        System.out.println(good.getGoodName());
	    } catch (Exception e) {
	        System.out.println("查询部门数据异常，请检查"); 
	    }
	}
	
}